
$(function () {
    var vue = new Vue({
        el: '.forget_password_content',
        data: {
            phone: '',   // 手机号
            infoCode: '',   // 短信验证码
            newPassWord: '', // 新密码
        },
        methods: {
            // 切换是否能看到密码
            toggleLook: function () {
                if ($('.look img').attr('src') == '../../img/not-look.png') {
                    $('.look img').attr('src','../../img/look.png');
                    $('.pass-word').attr('type','text')
                }
                else {
                    $('.look img').attr('src','../../img/not-look.png');
                    $('.pass-word').attr('type','password')
                }

            },
            // 获取短信验证码
            gainCode: function () {
                var _phone = this.phone;
                if(_phone.length == ''){
                    layer.msg("手机号不能为空");
                    return;
                }
                else if (!(/^1[3|4|5|7|8][0-9]{9}$/.test(_phone))){
                    layer.msg("手机号错误");
                    return;
                }
                else if ((/^170[0-9]{8}$/.test(_phone))){
                    layer.msg("很抱歉，受服务限制您的手机号无法注册")
                    return;
                }

                // 倒计时
                var time = 60;
                $('.get-code').hide();
                $('.count-down').show();
                $('.count-down span').html(time)
                var iCount = setInterval(function () {
                    if( time > 0) {
                        time --;
                        $('.count-down span').html(time)
                    } else {
                        clearInterval(iCount);
                        $('.get-code').show();
                        $('.count-down').hide();
                    }
                },1000);
                
            },
            // 确定
            forgetSubmit: function () {
                var _newPassWord = this.newPassWord   ;
                var _infoCode = this.infoCode;
                var regEn = /[`~!@#$%^&*()_+<>?:"{},.\/;'[\]]/im,
                    regCn = /[·！#￥（——）：；“”‘、，|《。》？、【】[\]]/im;
                if (_infoCode == '') {
                    layer.msg("短信验证码不能为空");
                    return;
                }
                else if (_newPassWord.length<6) {
                    layer.msg("密码不能小于6位");
                    return;
                }
                else if (_newPassWord.length>15) {
                    layer.msg("密码不能大于15位");
                    return;
                }
                else if (regEn.test(_newPassWord) || regCn.test(_newPassWord)) {
                    layer.msg("密码不能包含特殊字符");
                    return;
                }
            }
        }
    });
})
